package server;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    private Socket socket;

    public Client() {
        try {
            System.out.println("正在连接服务端>>>");
            socket = new Socket("192.168.1.114", 8090);
            System.out.println("服务端连接成功!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void start() {
        try {
            OutputStream os = socket.getOutputStream();  //将socket获取的输出流写出的字节发送给远端计算机---低级流
            OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8");   //将低级流转为高级流,选择字符集UTF-8
            BufferedWriter bw = new BufferedWriter(osw);            //高级流,提速
            PrintWriter pw = new PrintWriter(bw, true);         //第二个参数为TRUE时自动flush()
            Scanner scanner = new Scanner(System.in);
            String str;
            while (true) {
                System.out.println("请输入:");
                str = scanner.nextLine();
                pw.println(str);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        Client client = new Client();
        client.start();
    }
}
